@ecHo off

:: 检查必要文件
if not exist "in.txt" (
    ecHo nofind in.txt
    timeout /t 3 >nul
    exit /b 1
)

:: 如果有源代码则重新编译
if exist "C.cpp" (
    ecHo compiling C.cpp...
    g++ -std=c++14 -O2 -Wall -o C.exe C.cpp
    if %errorlevel% neq 0 (
        ecHo compiling error
        timeout /t 5 >nul
        exit /b 1
    )
)

:: 检查可执行文件是否存在
if exist "C.exe" (
    set executable=C.exe
) else if exist "C.out" (
    set executable=C.out
) else (
    ecHo wafind C.exe 或 C.out
    timeout /t 5 >nul
    exit /b 1
)

:: 运行程序
ecHo runing...
.\C.exe < in.txt > out.txt 2>&1

:: 检查执行结果
if %errorlevel% equ 0 (
    ecHo ok out.txt
) else (
    ecHo notok out.txt
)

timeout /t 10 >nul